<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Whistle Bridge 插件</title>
    <script>
      var webSocket = new WebSocket('ws://local.whistlejs.com/plugin.bridge/ws');
      // 监听连接开启
      webSocket.onopen = function (evt) {
        console.log('open');
      };
      // 监听websocket通讯
      webSocket.onmessage = function (evt) {
        // 这是服务端返回的数据
        let res = JSON.parse(evt.data);
        console.log(res);
      };
      // 监听连接关闭
      webSocket.onclose = function (evt) {
        console.log('Connection closed.');
      };

      window.wb = webSocket;
      // @example
      // wb.send(JSON.stringify({type:'exec',data:'alert(1)'}))
    </script>
  </head>
  <body>
    <input id="code" type="text" value="alert(1)" placeholder="执行代码" />
    <button onclick="wb.send(JSON.stringify({type:'exec',data:document.querySelector('#code').value}))">确定</button>
    Whistle Plugin UI Demo.
  </body>
</html>
